import sys
from PyQt5.QtWidgets import QApplication
from ui import LoginDialog, PointCloudMainWindow
from db.db_util import DBUtil

def main():
    """程序入口"""
    app = QApplication(sys.argv)

    # 显示登录窗口
    login_dialog = LoginDialog()
    if login_dialog.exec_() == LoginDialog.Accepted:
        # 登录成功，获取用户名和角色
        username = login_dialog.username_edit.text().strip()
        user = DBUtil.query_user(username)
        if not user:
            print("登录失败：用户信息获取异常")
            return 1

        # 启动主窗口
        main_window = PointCloudMainWindow()
        main_window.show()
        sys.exit(app.exec_())
    else:
        # 取消登录，退出程序
        print("用户取消登录")
        sys.exit(0)

if __name__ == "__main__":
    main()